package com.intellagric.controller.module.ift_equipment;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.module.iftmonitor.EquipmentStatusVo;
import com.intellagric.pojo.IftEquipmentBreakdownWithBLOBs;
import com.intellagric.service.iftmonitor.ift_equipment.EquipmentBreakdownService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/23
 * @DESC： 设备故障信息管理
 */
@Controller
public class EquipmentBreakdownController {

    @Autowired
    private EquipmentBreakdownService equipmentBreakdownService;

    /**
     * 添加设备故障信息
     * @Param
     * @return ResponseMessage
     */
    @RequestMapping("/equipment/breakdown/add")
    @ResponseBody
    public ResponseMessage add(IftEquipmentBreakdownWithBLOBs equipmentBreakdownWithBLOBs) {
        equipmentBreakdownWithBLOBs.setId(UUID.randomUUID().toString().replaceAll("-",""));
        equipmentBreakdownWithBLOBs.setCreateDate(new Date());
        equipmentBreakdownWithBLOBs.setUpdateDate(new Date());
        return equipmentBreakdownService.addEquipmentBreakdown(equipmentBreakdownWithBLOBs);
    }


    /**
     * 删除设备故障信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/equipment/breakdown/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return equipmentBreakdownService.deleteEquipmentBreakdown(id);
    }

    /**
     * 修改设备故障信息
     * @Param equipmentBreakdownWithBLOBs
     * @return ResponseMessage
     */
    @RequestMapping("/equipment/breakdown/edit")
    @ResponseBody
    public ResponseMessage edit(IftEquipmentBreakdownWithBLOBs equipmentBreakdownWithBLOBs) {
        equipmentBreakdownWithBLOBs.setCreateDate(null);
        equipmentBreakdownWithBLOBs.setUpdateDate(new Date());
        return equipmentBreakdownService.editEquipmentBreakdown(equipmentBreakdownWithBLOBs);
    }

    /**
     * 查询设备故障信息
     * @return IftEquipmentBreakdownWithBLOBs
     */
    @RequestMapping("/equipment/breakdown/{id}")
    @ResponseBody
    public IftEquipmentBreakdownWithBLOBs get(@PathVariable String id) {
        return equipmentBreakdownService.getEquipmentBreakdownById(id);
    }

    /**
     * 查询设备故障信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/equipment/breakdown/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return equipmentBreakdownService.getEquipmentBreakdownList();
    }

    /**
     * 多条件查询设备故障信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/equipment/breakdown/query")
    @ResponseBody
    public LayuiDataGridResult getListByVo(EquipmentStatusVo equipmentStatusVo) {
        return equipmentBreakdownService.getEquipmentBreakdownListByVo(equipmentStatusVo);
    }

    /**
     * 分页查询设备故障信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/equipment/breakdown/page")
    @ResponseBody
    public LayuiDataGridResult getPage(int page,int limit) {
        return equipmentBreakdownService.getEquipmentBreakdownPage(page,limit);
    }

}
